// pages/movies/movie-detail/movie-detail.js
var app = getApp()
var util = require('../../../utils/util')
Page({

  /**
   * 页面的初始数据
   */
  data: {},

  /**
   * 生命周期函数--监听页面加载
   * /v2/movie/subject/:id
   */
  onLoad: function (options) {
    let movieId = options.movieId
    let url = app.globalData.doubanBase + "/v2/movie/subject/" + movieId
    util.http(url, this.processDoubanData)
  },

  processDoubanData (data) {
    if (!data) {
      return
    }
    let director = {
      avatar: "",
      name: ""
    }
    if (data.directors[0] != null) {
      if (data.directors[0].avatars.large != null) {
        director.avatar = data.directors[0].avatar.large
      }
      director.name = data.directors[0].name
    }
    let movie = {
      id: data.id,
      movieImg: data.images.large ? data.images.large : "",
      country: data.countries[0],
      title: data.title,
      originalTitle: data.original_title,
      wishCount: data.wish_count,
      commentCount: data.comments_count,
      year: data.year,
      genres: data.genres.join("、"),
      stars: util.convertToStarsArray(data.rating.stars),
      score: data.rating.average,
      director: director,
      casts: util.convertToCastString(data.casts),
      castsInfo: util.convertToCastInfos(data.casts),
      summary: data.summary
    }
    this.setData(movie)
  },
  viewMoviePostImg (event) {
    let src = event.currentTarget.dataset.src
    wx.previewImage({
      current: src,  //当前显示图片的http链接
      urls: [src] //需要预览的图片http链接列表
      
    })
  }
  
})